<!--<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
  import LoginForm from '_c/login-form'
  import { mapActions } from 'vuex'
  export default {
    components: {
      LoginForm
    },
    methods: {
      ...mapActions([
        'handleLogin',
        'getUserInfo'
      ]),
      handleSubmit ({ userName, password }) {
        this.handleLogin({ userName, password }).then(res => {
          console.log(22,this.$config.homeName)
          this.getUserInfo().then(res => {
            console.log(11,res)
            this.$router.push({
              name: this.$config.homeName
            })
          })
        })
      }
    }
  }
</script>

<style>

</style>-->

<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
import { getUserInfo, login, selectUserPermissionTree } from '@/api/user-api'
import { localSave, localRead, setToken } from '@/libs/util'

export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit ({ userName, password }) {
      let data = {
        clientId: 'client',
        clientSecret: '123456',
        scope: 'app',
        grantType: 'password',
        userName: userName,
        password: password
      }
      login(data).then(res => {
        console.log(res)
        setToken('bearer ' + res.access_token)
        getUserInfo().then(res => {
          this.$router.push({
            name: this.$config.homeName
          })
        })
        selectUserPermissionTree().then(res => {
          let per = res.data
          localSave('userPermission', JSON.stringify(per))
        })
      })
    }
  }
}
</script>

<style>

</style>
